import 'dart:async';

import 'package:flutter_jd/service/global_service.dart';
import 'package:flutter_jd/tools/utils/library.dart';
import 'package:flutter_jd/tools/utils/storage.dart';
import 'package:flutter_jd/ui/widgets/body/tab_navigator.dart';
import 'package:flutter_jd/ui/widgets/kit.dart';
import 'package:get/get.dart';
import 'package:get/get_state_manager/get_state_manager.dart';

class LoginController extends GetxController {
  final agree = RxBool(false); // 是否同意隐私协议

  login() {
    if (agree.value) {
      Kit.showLoading();
      Timer(Duration(milliseconds: 1000), () {
        Kit.hideLoading();
        StorageUtil().setBool('isLogin', true);

        // 更新全局登录状态
        GlobalConfigService gcs = Get.find();
        gcs.setLoginStatus(true);

        Get.off(
          () => TabNavigator(),
          transition: Transition.noTransition,
        );
      });
    } else {
      Kit.showToast(text: '请阅读并勾选页面协议');
    }
  }
}
